package one.stand.controller;

import com.github.pagehelper.PageInfo;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import one.stand.model.ResultModel;
import one.stand.request.essay.EssayTypeForm;
import one.stand.request.essay.EssayTypeQuery;
import one.stand.request.essay.EssayTypeRequest;
import one.stand.response.essay.EssayTypeResponse;
import one.stand.service.EssayTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 获客文章类型相关业务
 * @author luoyang
 * @date 2020/5/6 16:40
 */
@RestController
@RequestMapping("essayType")
@Slf4j
public class EssayTypeController {

    @Autowired
    private EssayTypeService essayTypeService;
    /**
     * 创建获客文章类型
     * @param request
     * @return
     */
    @PostMapping("add")
    public ResultModel<Boolean> add(@RequestBody @Valid EssayTypeRequest request){
        log.info("add:{}",request);
        return essayTypeService.insert(request);
    }

    /**
     * 更新获客文章类型
     * @param request
     * @return
     */
    @PostMapping("update")
    public ResultModel<Boolean> update(@RequestBody @Valid EssayTypeForm request){
        log.info("update:{}",request);
        return essayTypeService.update(request);
    }

    /**
     * 查询获客文章类型
     * @param request
     * @return
     */
    @PostMapping("queryById")
    public ResultModel<EssayTypeResponse> queryById(@RequestBody @Valid EssayTypeRequest request){
        log.info("queryById:{}",request);
        return essayTypeService.queryById(request.getEssayTypeId());
    }

    /**
     * 删除分类
     * @param request
     * @return
     */
    @PostMapping("deleteById")
    public ResultModel<Boolean> deleteById(@RequestBody @Valid EssayTypeQuery request){
        log.info("deleteById:{}",request);
        return essayTypeService.deleteById(request.getEssayTypeId());
    }


    /**
     * 分页查询获客文章类型
     * @param request
     * @return
     */
    @PostMapping("queryPage")
    public ResultModel<PageInfo<EssayTypeResponse>> queryPage(@RequestBody @Valid EssayTypeQuery request){
        log.info("queryPage:{}",request);
        return essayTypeService.queryPage(request);
    }

    /**
     * 查询当前公司下的所有分类
     * @param request
     * @return
     */
    @PostMapping("queryAllType")
    public ResultModel<List<EssayTypeResponse>> queryAllType(@RequestBody @Valid EssayTypeQuery request){
        log.info("queryAllType:{}",request);
        return essayTypeService.queryAllType(request);
    }

}
